package com.ciwong.epaper.modules.epaper.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.epaper.bean.EpaperInfo;
import com.ciwong.epaper.modules.me.adapter.BaseCommonAdapter;
import com.ciwong.epaper.util.EConstants;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by yyf on 2017/8/17.
 */

public class ChooseServiceAdapter extends BaseCommonAdapter {
    public ChooseServiceAdapter(List<EpaperInfo.Server> dataList) {
        super(dataList);
    }

    @Override
    public int getItemResId(int position) {
        return R.layout.item_choose_service;
    }

    @Override
    public Object createViewHolder(View convertView, int position) {
        ViewHolder viewHolder = new ViewHolder();
        viewHolder.iv_icon = (ImageView) convertView.findViewById(R.id.iv_icon);
        viewHolder.tv_title = (TextView) convertView.findViewById(R.id.tv_service_name);
        viewHolder.tv_all = (TextView) convertView.findViewById(R.id.rl_all);
        return viewHolder;
    }

    @Override
    public void showData(Object bean, Object holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        EpaperInfo.Server server = (EpaperInfo.Server) bean;
        viewHolder.tv_title.setText(server.getName());
        try {
            if(server.getName().equals("全部书籍")){
                viewHolder.tv_all.setVisibility(View.VISIBLE);
                viewHolder.iv_icon.setVisibility(View.GONE);
            }else{
                viewHolder.tv_all.setVisibility(View.GONE);
                viewHolder.iv_icon.setVisibility(View.VISIBLE);
                ImageLoader.getInstance().displayImage(server.getLogo(), viewHolder.iv_icon, EConstants.getDefAvatarCircleBuilder());

            }
//            ImageLoader.getInstance().displayImage(checkValidServiceBean.logo, new ImageViewAware(viewHolder.iv_service_logo), EConstants.getBookCoverOption());
        } catch (OutOfMemoryError error) {

        }
    }

    class ViewHolder {
        public ImageView iv_icon;
        public TextView tv_title;
        public TextView tv_all;
    }
}
